Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions cmd/vcr-compressor/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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])
}

chemin := os.Args[1]

inputCassette, err := cassette.Load(chemin)
if err != nil {
log.Fatalf("Error while reading file : %v\n", err)
}

outputCassette := cassette.New(chemin)
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
}

if m["status"] != nil {
// We test if the state is transient
if _, ok := transientStates[m["status"].(string)]; 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, m["status"])

continue
} else {
transitioning = true

log.Printf("Interaction %d is in a transient state: %s, Recording it\n", i, m["status"])
outputCassette.AddInteraction(interaction)
}
} else {
if transitioning {
log.Printf("Interaction %d is not in a transient state anymore: %s, Recording it\n", i, m["status"])
outputCassette.AddInteraction(interaction)

transitioning = false
} else {
log.Printf("Interaction %d is not in a transient state: %s, Recording it\n", i, m["status"])
outputCassette.AddInteraction(interaction)
}
}
}
}

err = outputCassette.Save()
if err != nil {
log.Fatalf("error while saving file: %v", err)
}
}
55 changes: 55 additions & 0 deletions cmd/vcr-viewer/main.go
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])
}

chemin := os.Args[1]

data, err := cassette.Load(chemin)
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"]) // Modifie le champ "status" pour qu'il soit "ok"
log.Println("++++++++++++++++")
}

log.Println("--------------")
}
}
6,798 changes: 165 additions & 6,633 deletions internal/services/k8s/testdata/cluster-multicloud.cassette.yaml

Large diffs are not rendered by default.

5,519 changes: 2,013 additions & 3,506 deletions internal/services/k8s/testdata/cluster-pool-private-network.cassette.yaml

Large diffs are not rendered by default.

10,834 changes: 664 additions & 10,170 deletions internal/services/k8s/testdata/cluster-type-change.cassette.yaml

Large diffs are not rendered by default.

6,713 changes: 245 additions & 6,468 deletions internal/services/k8s/testdata/data-source-cluster-basic.cassette.yaml

Large diffs are not rendered by default.

6,571 changes: 566 additions & 6,005 deletions internal/services/k8s/testdata/data-source-pool-basic.cassette.yaml

Large diffs are not rendered by default.

7,453 changes: 566 additions & 6,887 deletions internal/services/k8s/testdata/pool-basic.cassette.yaml

Large diffs are not rendered by default.

6,119 changes: 291 additions & 5,828 deletions internal/services/k8s/testdata/pool-kubelet-args.cassette.yaml

Large diffs are not rendered by default.

17,737 changes: 857 additions & 16,880 deletions internal/services/k8s/testdata/pool-placement-group.cassette.yaml

Large diffs are not rendered by default.

12,510 changes: 522 additions & 11,988 deletions internal/services/k8s/testdata/pool-public-ip-disabled.cassette.yaml

Large diffs are not rendered by default.

5,580 changes: 242 additions & 5,338 deletions internal/services/k8s/testdata/pool-size.cassette.yaml

Large diffs are not rendered by default.

7,344 changes: 291 additions & 7,053 deletions internal/services/k8s/testdata/pool-upgrade-policy.cassette.yaml

Large diffs are not rendered by default.

11,487 changes: 1,015 additions & 10,472 deletions internal/services/k8s/testdata/pool-wait.cassette.yaml

Large diffs are not rendered by default.

Loading
Loading