-
Notifications
You must be signed in to change notification settings - Fork 131
chore: add support for vcr compression and trim k8s cassettes #3136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
f406ed3
0f14c82
2033540
5a99dd0
b279bfa
53f055d
ac76827
b518d24
c90db79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
"github.com/scaleway/scaleway-sdk-go/api/k8s/v1" | ||
"gopkg.in/dnaeon/go-vcr.v3/cassette" | ||
) | ||
|
||
var transientStates = map[string]bool{ | ||
k8s.ClusterStatusCreating.String(): true, | ||
k8s.ClusterStatusDeleting.String(): true, | ||
k8s.ClusterStatusUpdating.String(): true, | ||
k8s.PoolStatusDeleting.String(): true, | ||
k8s.PoolStatusScaling.String(): true, | ||
k8s.PoolStatusUpgrading.String(): true, | ||
} | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatalf("Usage: %s <cassette_file_name_without_yaml>\n", os.Args[0]) | ||
} | ||
|
||
path := os.Args[1] | ||
|
||
inputCassette, err := cassette.Load(path) | ||
if err != nil { | ||
log.Fatalf("Error while reading file : %v\n", err) | ||
} | ||
|
||
outputCassette := cassette.New(path) | ||
transitioning := false | ||
|
||
for i := range len(inputCassette.Interactions) { | ||
interaction := inputCassette.Interactions[i] | ||
responseBody := interaction.Response.Body | ||
requestMethod := interaction.Request.Method | ||
|
||
if requestMethod != "GET" { | ||
transitioning = false | ||
|
||
log.Printf("Interaction %d is not a GET request. Recording it\n", i) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
if responseBody == "" { | ||
log.Printf("Interaction %d got an empty response body. Recording it\n", i) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
var m map[string]interface{} | ||
|
||
err := json.Unmarshal([]byte(responseBody), &m) | ||
if err != nil { | ||
log.Printf("Interaction %d have an error with unmarshalling response body: %v. Recording it\n", i, err) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
if m["status"] == nil { | ||
log.Printf("Interaction %d does not contain a status field. Recording it\n", i) | ||
outputCassette.AddInteraction(interaction) | ||
|
||
continue | ||
} | ||
|
||
status := m["status"].(string) | ||
Gnoale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// We test if the state is transient | ||
if _, ok := transientStates[status]; ok { | ||
if transitioning { | ||
log.Printf("Interaction %d is in a transient state while we are already in transitient state. No need to record it: %s\n", i, status) | ||
|
||
continue | ||
} else { | ||
log.Printf("Interaction %d is in a transient state: %s, Recording it\n", i, status) | ||
|
||
transitioning = true | ||
|
||
outputCassette.AddInteraction(interaction) | ||
} | ||
} else { | ||
if transitioning { | ||
log.Printf("Interaction %d is not in a transient state anymore: %s, Recording it\n", i, status) | ||
|
||
outputCassette.AddInteraction(interaction) | ||
|
||
transitioning = false | ||
} else { | ||
log.Printf("Interaction %d is not in a transient state: %s, Recording it\n", i, status) | ||
outputCassette.AddInteraction(interaction) | ||
} | ||
} | ||
} | ||
|
||
err = outputCassette.Save() | ||
if err != nil { | ||
log.Fatalf("error while saving file: %v", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
"gopkg.in/dnaeon/go-vcr.v3/cassette" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatalf("Usage: %s <cassette_file_name_without_yaml>\n", os.Args[0]) | ||
} | ||
|
||
path := os.Args[1] | ||
|
||
data, err := cassette.Load(path) | ||
if err != nil { | ||
log.Fatalf("Error while reading file: %v\n", err) | ||
} | ||
|
||
for i := range len(data.Interactions) { | ||
interaction := data.Interactions[i] | ||
|
||
log.Println("--------------") | ||
log.Printf("Interaction %d:\n", i+1) | ||
log.Printf(" Request:\n") | ||
log.Printf(" Method: %s\n", interaction.Request.Method) | ||
log.Printf(" URL: %s\n", interaction.Request.URL) | ||
|
||
if interaction.Request.Body != "" { | ||
log.Printf(" Body: %s\n", interaction.Request.Body) | ||
} | ||
|
||
log.Printf(" Response:\n") | ||
log.Printf(" Status: %s\n", interaction.Response.Status) | ||
log.Printf(" Body: %s\n", interaction.Response.Body) | ||
|
||
var m map[string]interface{} | ||
|
||
err := json.Unmarshal([]byte(interaction.Response.Body), &m) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
if m["status"] != nil { | ||
log.Println("++++++++++++++++") | ||
log.Printf("status: %s\n", m["status"]) | ||
log.Println("++++++++++++++++") | ||
} | ||
|
||
log.Println("--------------") | ||
} | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.