Skip to content

Commit

Permalink
fix environment migration (#2534)
Browse files Browse the repository at this point in the history
* migrate environment usage to use new resource structure

* fix env apply and add test to server env model

* fix stuff

* fix tests

* delete old environment struct

* PR suggestions

* remove json fallback

* use pointer to repository instead of passing by value

* fix test
  • Loading branch information
mathnogueira authored and schoren committed Jun 5, 2023
1 parent 0971831 commit 24559da
Show file tree
Hide file tree
Showing 41 changed files with 232 additions and 1,208 deletions.
11 changes: 6 additions & 5 deletions cli/actions/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/kubeshop/tracetest/cli/file"
"github.com/kubeshop/tracetest/cli/openapi"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/kubeshop/tracetest/server/environment"
"github.com/kubeshop/tracetest/server/model/yaml"
"github.com/mitchellh/mapstructure"
)
Expand All @@ -34,8 +35,8 @@ func (environmentsActions) Name() string {
return "environment"
}

func (environment environmentsActions) GetID(file *file.File) (string, error) {
resource, err := environment.formatter.ToStruct(file)
func (action environmentsActions) GetID(file *file.File) (string, error) {
resource, err := action.formatter.ToStruct(file)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -85,7 +86,7 @@ func (environment environmentsActions) ApplyResource(ctx context.Context, resour
return environment.Apply(ctx, file)
}

func (environment environmentsActions) FromFile(ctx context.Context, filePath string) (openapi.EnvironmentResource, error) {
func (action environmentsActions) FromFile(ctx context.Context, filePath string) (openapi.EnvironmentResource, error) {
if !utils.StringReferencesFile(filePath) {
return openapi.EnvironmentResource{}, fmt.Errorf(`env file "%s" does not exist`, filePath)
}
Expand All @@ -100,7 +101,7 @@ func (environment environmentsActions) FromFile(ctx context.Context, filePath st
return openapi.EnvironmentResource{}, fmt.Errorf(`cannot parse env file "%s": %w`, filePath, err)
}

envModel := model.Spec.(yaml.Environment)
envModel := model.Spec.(environment.Environment)

values := make([]openapi.EnvironmentValue, 0, len(envModel.Values))
for _, value := range envModel.Values {
Expand All @@ -114,7 +115,7 @@ func (environment environmentsActions) FromFile(ctx context.Context, filePath st
environmentResource := openapi.EnvironmentResource{
Type: (*string)(&model.Type),
Spec: &openapi.Environment{
Id: &envModel.ID,
Id: openapi.PtrString(envModel.ID.String()),
Name: &envModel.Name,
Description: &envModel.Description,
Values: values,
Expand Down
4 changes: 2 additions & 2 deletions cli/formatters/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package formatters

import (
"github.com/alexeyco/simpletable"
"github.com/goccy/go-yaml"
"github.com/kubeshop/tracetest/cli/file"
"github.com/kubeshop/tracetest/cli/openapi"
)
Expand Down Expand Up @@ -54,9 +55,8 @@ func (f EnvironmentsFormatter) ToListTable(file *file.File) (*simpletable.Header

func (f EnvironmentsFormatter) ToStruct(file *file.File) (interface{}, error) {
var environmentResource openapi.EnvironmentResource
nullableEnvironment := openapi.NewNullableEnvironmentResource(&environmentResource)

err := nullableEnvironment.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &environmentResource)
if err != nil {
return nil, err
}
Expand Down
18 changes: 4 additions & 14 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/cucumber/ci-environment/go v0.0.0-20220915001957-711b1c82415f
github.com/denisbrodbeck/machineid v1.0.1
github.com/goccy/go-yaml v1.11.0
github.com/kubeshop/tracetest/server v0.0.0-20230208220354-63c9594b2160
github.com/kubeshop/tracetest/server v0.0.0-20230512142545-cb5e526e06f9
github.com/mitchellh/mapstructure v1.5.0
github.com/pterm/pterm v0.12.55
github.com/segmentio/analytics-go/v3 v3.2.1
Expand All @@ -24,6 +24,7 @@ require (
require (
atomicgo.dev/cursor v0.1.1 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand All @@ -32,35 +33,25 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fluidtruck/deepcopy v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gookit/color v1.5.2 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.10 // indirect
github.com/knadh/koanf v1.4.3 // indirect
github.com/lithammer/fuzzysearch v1.1.5 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mostynb/go-grpc-compression v1.1.17 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -80,18 +71,17 @@ require (
go.opentelemetry.io/collector v0.60.0 // indirect
go.opentelemetry.io/collector/pdata v0.60.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.9.0 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/metric v0.32.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
google.golang.org/grpc v1.52.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading

0 comments on commit 24559da

Please sign in to comment.