Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erka committed Sep 18, 2024
1 parent 6f8d028 commit d804d78
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 91 deletions.
16 changes: 8 additions & 8 deletions build/testing/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {
}

assert.Equal(t, ruleTwo.Id, distribution.RuleId)
assert.Equal(t, float32(100), distribution.Rollout)
assert.InDelta(t, 100, distribution.Rollout, 0)

distribution, err = client.Flipt().CreateDistribution(ctx, &flipt.CreateDistributionRequest{
NamespaceKey: namespace.Key,
Expand Down Expand Up @@ -733,7 +733,7 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {
assert.Equal(t, "boolean_disabled", rolloutSegment.FlagKey)
assert.Equal(t, int32(1), rolloutSegment.Rank)
assert.Equal(t, "everyone", rolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.SegmentKey)
assert.Equal(t, true, rolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.Value)
assert.True(t, rolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.Value)

anotherRolloutSegment, err := client.Flipt().CreateRollout(ctx, &flipt.CreateRolloutRequest{
NamespaceKey: namespace.Key,
Expand All @@ -753,7 +753,7 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {
assert.Equal(t, "boolean_disabled", anotherRolloutSegment.FlagKey)
assert.Equal(t, int32(2), anotherRolloutSegment.Rank)
assert.Equal(t, "another-segment", anotherRolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.SegmentKey)
assert.Equal(t, false, anotherRolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.Value)
assert.False(t, anotherRolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.Value)

updatedAnotherRolloutSegment, err := client.Flipt().UpdateRollout(ctx, &flipt.UpdateRolloutRequest{
Id: anotherRolloutSegment.Id,
Expand All @@ -773,7 +773,7 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {
assert.Equal(t, int32(2), updatedAnotherRolloutSegment.Rank)
assert.Contains(t, updatedAnotherRolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.SegmentKeys, "segment")
assert.Contains(t, updatedAnotherRolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.SegmentKeys, "another-segment")
assert.Equal(t, false, updatedAnotherRolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.Value)
assert.False(t, updatedAnotherRolloutSegment.Rule.(*flipt.Rollout_Segment).Segment.Value)

rolloutThreshold, err := client.Flipt().CreateRollout(ctx, &flipt.CreateRolloutRequest{
NamespaceKey: namespace.Key,
Expand All @@ -793,8 +793,8 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {
assert.Equal(t, "boolean_disabled", rolloutThreshold.FlagKey)
assert.Equal(t, "50% disabled", rolloutThreshold.Description)
assert.Equal(t, int32(3), rolloutThreshold.Rank)
assert.Equal(t, float32(50.0), rolloutThreshold.Rule.(*flipt.Rollout_Threshold).Threshold.Percentage)
assert.Equal(t, true, rolloutThreshold.Rule.(*flipt.Rollout_Threshold).Threshold.Value)
assert.InDelta(t, 50.0, rolloutThreshold.Rule.(*flipt.Rollout_Threshold).Threshold.Percentage, 0)
assert.True(t, rolloutThreshold.Rule.(*flipt.Rollout_Threshold).Threshold.Value)

t.Log(`Ensure multiple rollouts with same rank can not be created`)

Expand Down Expand Up @@ -874,8 +874,8 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {
assert.Equal(t, "boolean_disabled", updatedRollout.FlagKey)
assert.Equal(t, "50% enabled", updatedRollout.Description)
assert.Equal(t, int32(3), updatedRollout.Rank)
assert.Equal(t, float32(50.0), updatedRollout.Rule.(*flipt.Rollout_Threshold).Threshold.Percentage)
assert.Equal(t, false, updatedRollout.Rule.(*flipt.Rollout_Threshold).Threshold.Value)
assert.InDelta(t, 50.0, updatedRollout.Rule.(*flipt.Rollout_Threshold).Threshold.Percentage, 0)
assert.False(t, updatedRollout.Rule.(*flipt.Rollout_Threshold).Threshold.Value)

t.Run("Cannot change rollout type", func(t *testing.T) {
_, err := client.Flipt().UpdateRollout(ctx, &flipt.UpdateRolloutRequest{
Expand Down
24 changes: 12 additions & 12 deletions build/testing/integration/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ func TestReadOnly(t *testing.T) {
require.Len(t, rule.Distributions, 2)

assert.NotEmpty(t, rule.Distributions[0].Id)
assert.Equal(t, float32(50.0), rule.Distributions[0].Rollout)
assert.InDelta(t, 50.0, rule.Distributions[0].Rollout, 0)
assert.NotEmpty(t, rule.Distributions[1].Id)
assert.Equal(t, float32(50.0), rule.Distributions[1].Rollout)
assert.InDelta(t, 50.0, rule.Distributions[1].Rollout, 0)
})

t.Run("ListRules", func(t *testing.T) {
Expand Down Expand Up @@ -268,9 +268,9 @@ func TestReadOnly(t *testing.T) {
require.Len(t, rule.Distributions, 2)

assert.NotEmpty(t, rule.Distributions[0].Id)
assert.Equal(t, float32(50.0), rule.Distributions[0].Rollout)
assert.InDelta(t, 50.0, rule.Distributions[0].Rollout, 0)
assert.NotEmpty(t, rule.Distributions[1].Id)
assert.Equal(t, float32(50.0), rule.Distributions[1].Rollout)
assert.InDelta(t, 50.0, rule.Distributions[1].Rollout, 0)

t.Run("Paginated (page size 10)", func(t *testing.T) {
var (
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestReadOnly(t *testing.T) {
})
require.NoError(t, err)

assert.Equal(t, true, response.Match)
assert.True(t, response.Match)
assert.Equal(t, "variant_002", response.Value)
assert.Equal(t, flipt.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
})
Expand Down Expand Up @@ -401,11 +401,11 @@ func TestReadOnly(t *testing.T) {
require.NoError(t, err)
require.Len(t, response.Responses, 2)

assert.Equal(t, true, response.Responses[0].Match)
assert.True(t, response.Responses[0].Match)
assert.Equal(t, "variant_002", response.Responses[0].Value)
assert.Equal(t, flipt.EvaluationReason_MATCH_EVALUATION_REASON, response.Responses[0].Reason)

assert.Equal(t, true, response.Responses[1].Match)
assert.True(t, response.Responses[1].Match)
assert.Equal(t, "variant_001", response.Responses[1].Value)
assert.Equal(t, flipt.EvaluationReason_MATCH_EVALUATION_REASON, response.Responses[1].Reason)
})
Expand All @@ -424,7 +424,7 @@ func TestReadOnly(t *testing.T) {
})
require.NoError(t, err)

assert.Equal(t, true, response.Match)
assert.True(t, response.Match)
assert.Equal(t, "flag_001", response.FlagKey)
assert.Equal(t, "variant_002", response.VariantKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
Expand All @@ -443,7 +443,7 @@ func TestReadOnly(t *testing.T) {
})
require.NoError(t, err)

assert.Equal(t, true, response.Match)
assert.True(t, response.Match)
assert.Equal(t, "variant_002", response.VariantKey)
assert.Equal(t, "flag_variant_and_segments", response.FlagKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
Expand All @@ -462,7 +462,7 @@ func TestReadOnly(t *testing.T) {
})
require.NoError(t, err)

assert.Equal(t, false, response.Match)
assert.False(t, response.Match)
assert.Empty(t, response.VariantKey)
assert.Equal(t, evaluation.EvaluationReason_UNKNOWN_EVALUATION_REASON, response.Reason)
})
Expand All @@ -476,7 +476,7 @@ func TestReadOnly(t *testing.T) {
})
require.NoError(t, err)

assert.Equal(t, true, response.Match)
assert.True(t, response.Match)
assert.Equal(t, "variant_001", response.VariantKey)
assert.Equal(t, "flag_using_entity_id", response.FlagKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestReadOnly(t *testing.T) {
})
require.NoError(t, err)

assert.Equal(t, true, response.Match)
assert.True(t, response.Match)
assert.Equal(t, "flag_no_distributions", response.FlagKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
assert.Contains(t, response.SegmentKeys, "segment_001")
Expand Down
6 changes: 3 additions & 3 deletions internal/cache/memory/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ func TestDelete(t *testing.T) {
require.NoError(t, err)

v, ok, err := c.Get(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, ok)
assert.Equal(t, []byte("value"), v)

err = c.Delete(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)

v, ok, err = c.Get(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, ok)
assert.Nil(t, v)
}
16 changes: 8 additions & 8 deletions internal/cache/redis/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ func TestGet(t *testing.T) {
defer teardown()

err := c.Set(ctx, "key", []byte("value"))
assert.NoError(t, err)
require.NoError(t, err)

v, ok, err := c.Get(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, ok)
assert.Equal(t, []byte("value"), v)

v, ok, err = c.Get(ctx, "foo")
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, ok)
assert.Nil(t, v)

v, ok, err = c.Get(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, ok)
assert.Equal(t, []byte("value"), v)
}
Expand All @@ -64,18 +64,18 @@ func TestDelete(t *testing.T) {
defer teardown()

err := c.Set(ctx, "key", []byte("value"))
assert.NoError(t, err)
require.NoError(t, err)

v, ok, err := c.Get(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, ok)
assert.Equal(t, []byte("value"), v)

err = c.Delete(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)

v, ok, err = c.Get(ctx, "key")
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, ok)
assert.Nil(t, v)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.flipt.io/flipt/internal/config"
"go.flipt.io/flipt/internal/info"
"go.uber.org/zap/zaptest"
Expand All @@ -19,7 +20,7 @@ func TestNewGRPCServer(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
s, err := NewGRPCServer(ctx, zaptest.NewLogger(t), cfg, info.Flipt{}, false)
assert.NoError(t, err)
require.NoError(t, err)
t.Cleanup(func() {
err := s.Shutdown(ctx)
assert.NoError(t, err)
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -40,21 +41,21 @@ func TestTrailingSlashMiddleware(t *testing.T) {

// Request with the middleware on.
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, fmt.Sprintf("%s/hello/", s.URL), nil)
assert.NoError(t, err)
require.NoError(t, err)
req.Header.Set(tsoHeader, "on")

res, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, http.StatusOK, res.StatusCode)
require.Equal(t, http.StatusOK, res.StatusCode)
res.Body.Close()

// Request with the middleware off.
req, err = http.NewRequestWithContext(context.TODO(), http.MethodGet, fmt.Sprintf("%s/hello/", s.URL), nil)
assert.NoError(t, err)
require.NoError(t, err)

res, err = http.DefaultClient.Do(req)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, http.StatusNotFound, res.StatusCode)
res.Body.Close()
Expand Down
5 changes: 3 additions & 2 deletions internal/config/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAnalyticsClickhouseConfiguration(t *testing.T) {
Expand All @@ -17,13 +18,13 @@ func TestAnalyticsClickhouseConfiguration(t *testing.T) {
}
assert.True(t, cfg.Enabled())
options, err := cfg.Storage.Clickhouse.Options()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, []string{"localhost"}, options.Addr)
assert.Equal(t, "db", options.Auth.Database)

cfg.Storage.Clickhouse.URL = "something"
_, err = cfg.Storage.Clickhouse.Options()
assert.Error(t, err)
require.Error(t, err)
assert.ErrorContains(t, err, "parse dsn address failed")

}
10 changes: 5 additions & 5 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestScheme(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, want, scheme.String())
json, err := scheme.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)
assert.JSONEq(t, fmt.Sprintf("%q", want), string(json))
})
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestCacheBackend(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, want, backend.String())
json, err := backend.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)
assert.JSONEq(t, fmt.Sprintf("%q", want), string(json))
})
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestTracingExporter(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, want, exporter.String())
json, err := exporter.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)
assert.JSONEq(t, fmt.Sprintf("%q", want), string(json))
})
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestDatabaseProtocol(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, want, protocol.String())
json, err := protocol.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)
assert.JSONEq(t, fmt.Sprintf("%q", want), string(json))
})
}
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestLogEncoding(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, want, encoding.String())
json, err := encoding.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)
assert.JSONEq(t, fmt.Sprintf("%q", want), string(json))
})
}
Expand Down
14 changes: 7 additions & 7 deletions internal/ext/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,11 +1114,11 @@ func TestImport(t *testing.T) {
importer := NewImporter(creator)

in, err := os.Open(tc.path + "." + string(ext))
assert.NoError(t, err)
require.NoError(t, err)
defer in.Close()

err = importer.Import(context.Background(), ext, in, tc.skipExisting)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, tc.expected, creator)
})
Expand Down Expand Up @@ -1149,7 +1149,7 @@ func TestImport_InvalidVersion(t *testing.T) {

for _, ext := range extensions {
in, err := os.Open("testdata/import_invalid_version." + string(ext))
assert.NoError(t, err)
require.NoError(t, err)
defer in.Close()

err = importer.Import(context.Background(), ext, in, skipExistingFalse)
Expand All @@ -1165,7 +1165,7 @@ func TestImport_FlagType_LTVersion1_1(t *testing.T) {

for _, ext := range extensions {
in, err := os.Open("testdata/import_v1_flag_type_not_supported." + string(ext))
assert.NoError(t, err)
require.NoError(t, err)
defer in.Close()

err = importer.Import(context.Background(), ext, in, skipExistingFalse)
Expand All @@ -1181,7 +1181,7 @@ func TestImport_Rollouts_LTVersion1_1(t *testing.T) {

for _, ext := range extensions {
in, err := os.Open("testdata/import_v1_rollouts_not_supported." + string(ext))
assert.NoError(t, err)
require.NoError(t, err)
defer in.Close()

err = importer.Import(context.Background(), ext, in, skipExistingFalse)
Expand Down Expand Up @@ -1244,11 +1244,11 @@ func TestImport_Namespaces_Mix_And_Match(t *testing.T) {
)

in, err := os.Open(tc.path + "." + string(ext))
assert.NoError(t, err)
require.NoError(t, err)
defer in.Close()

err = importer.Import(context.Background(), ext, in, skipExistingFalse)
assert.NoError(t, err)
require.NoError(t, err)

assert.Len(t, creator.getNSReqs, tc.expectedGetNSReqs)
assert.Len(t, creator.createflagReqs, tc.expectedCreateFlagReqs)
Expand Down
Loading

0 comments on commit d804d78

Please sign in to comment.