From 4ed015497d99e688a886f6afcaa67ef867ee601b Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Fri, 17 Mar 2023 18:04:27 +0100 Subject: [PATCH] Fix lint/test issue (#561) --- cmd/relayproxy/config/config.go | 13 ++--- cmd/relayproxy/config/config_test.go | 68 +++++-------------------- cmd/relayproxy/service/gofeatureflag.go | 1 + 3 files changed, 22 insertions(+), 60 deletions(-) diff --git a/cmd/relayproxy/config/config.go b/cmd/relayproxy/config/config.go index afde3ee01f3..f79584bd9b6 100644 --- a/cmd/relayproxy/config/config.go +++ b/cmd/relayproxy/config/config.go @@ -15,7 +15,7 @@ var DefaultRetriever = struct { HTTPMethod string GithubBranch string }{ - Timeout: time.Duration(10 * time.Second), + Timeout: 10 * time.Second, HTTPMethod: http.MethodGet, GithubBranch: "main", } @@ -28,11 +28,12 @@ var DefaultExporter = struct { FlushInterval time.Duration MaxEventInMemory int64 }{ - Format: "JSON", - LogFormat: "[{{ .FormattedDate}}] user=\"{{ .UserKey}}\", flag=\"{{ .Key}}\", value=\"{{ .Value}}\"", - FileName: "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}", - CsvFormat: "{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};{{ .Value}};{{ .Default}}\\n", - FlushInterval: time.Duration(60000 * time.Millisecond), + Format: "JSON", + LogFormat: "[{{ .FormattedDate}}] user=\"{{ .UserKey}}\", flag=\"{{ .Key}}\", value=\"{{ .Value}}\"", + FileName: "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}", + CsvFormat: "{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};" + + "{{ .Value}};{{ .Default}}\\n", + FlushInterval: 60000 * time.Millisecond, MaxEventInMemory: 100000, } diff --git a/cmd/relayproxy/config/config_test.go b/cmd/relayproxy/config/config_test.go index 312b7740857..d201c1fafae 100644 --- a/cmd/relayproxy/config/config_test.go +++ b/cmd/relayproxy/config/config_test.go @@ -27,19 +27,11 @@ func TestParseConfig_fileFromPflag(t *testing.T) { FileFormat: "yaml", Host: "localhost", Retriever: &config.RetrieverConf{ - Kind: "http", - URL: "https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/examples/retriever_file/flags.yaml", - HTTPMethod: "GET", - Timeout: 10000, + Kind: "http", + URL: "https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/examples/retriever_file/flags.yaml", }, Exporter: &config.ExporterConf{ - Kind: "log", - Filename: "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}", - CsvTemplate: `{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};{{ .Value}};{{ .Default}}\n`, - Format: "JSON", - LogFormat: `[{{ .FormattedDate}}] user="{{ .UserKey}}", flag="{{ .Key}}", value="{{ .Value}}"`, - FlushInterval: 60000, - MaxEventInMemory: 100000, + Kind: "log", }, StartWithRetrieverError: false, RestAPITimeout: 5000, @@ -52,22 +44,10 @@ func TestParseConfig_fileFromPflag(t *testing.T) { name: "All default", fileLocation: "../testdata/config/all-default.yaml", want: &config.Config{ - ListenPort: 1031, - PollingInterval: 60000, - FileFormat: "yaml", - Host: "localhost", - Retriever: &config.RetrieverConf{ - HTTPMethod: "GET", - Timeout: 10000, - }, - Exporter: &config.ExporterConf{ - Filename: "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}", - CsvTemplate: `{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};{{ .Value}};{{ .Default}}\n`, - Format: "JSON", - LogFormat: `[{{ .FormattedDate}}] user="{{ .UserKey}}", flag="{{ .Key}}", value="{{ .Value}}"`, - FlushInterval: 60000, - MaxEventInMemory: 100000, - }, + ListenPort: 1031, + PollingInterval: 60000, + FileFormat: "yaml", + Host: "localhost", StartWithRetrieverError: false, RestAPITimeout: 5000, Version: "1.X.X", @@ -114,19 +94,11 @@ func TestParseConfig_fileFromFolder(t *testing.T) { FileFormat: "yaml", Host: "localhost", Retriever: &config.RetrieverConf{ - Kind: "http", - URL: "https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/examples/retriever_file/flags.yaml", - HTTPMethod: "GET", - Timeout: 10000, + Kind: "http", + URL: "https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/examples/retriever_file/flags.yaml", }, Exporter: &config.ExporterConf{ - Kind: "log", - Filename: "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}", - CsvTemplate: `{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};{{ .Value}};{{ .Default}}\n`, - Format: "JSON", - LogFormat: `[{{ .FormattedDate}}] user="{{ .UserKey}}", flag="{{ .Key}}", value="{{ .Value}}"`, - FlushInterval: 60000, - MaxEventInMemory: 100000, + Kind: "log", }, StartWithRetrieverError: false, RestAPITimeout: 5000, @@ -139,22 +111,10 @@ func TestParseConfig_fileFromFolder(t *testing.T) { name: "All default", fileLocation: "../testdata/config/all-default.yaml", want: &config.Config{ - ListenPort: 1031, - PollingInterval: 60000, - FileFormat: "yaml", - Host: "localhost", - Retriever: &config.RetrieverConf{ - HTTPMethod: "GET", - Timeout: 10000, - }, - Exporter: &config.ExporterConf{ - Filename: "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}", - CsvTemplate: `{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};{{ .Value}};{{ .Default}}\n`, - Format: "JSON", - LogFormat: `[{{ .FormattedDate}}] user="{{ .UserKey}}", flag="{{ .Key}}", value="{{ .Value}}"`, - FlushInterval: 60000, - MaxEventInMemory: 100000, - }, + ListenPort: 1031, + PollingInterval: 60000, + FileFormat: "yaml", + Host: "localhost", StartWithRetrieverError: false, RestAPITimeout: 5000, Version: "1.X.X", diff --git a/cmd/relayproxy/service/gofeatureflag.go b/cmd/relayproxy/service/gofeatureflag.go index 76d6a1bcd84..ace5f027d70 100644 --- a/cmd/relayproxy/service/gofeatureflag.go +++ b/cmd/relayproxy/service/gofeatureflag.go @@ -40,6 +40,7 @@ func NewGoFeatureFlagClient(proxyConf *config.Config, logger *zap.Logger) (*ffcl retrievers := make([]retriever.Retriever, 0) if proxyConf.Retrievers != nil { for _, r := range *proxyConf.Retrievers { + r := r currentRetriever, err := initRetriever(&r) if err != nil { return nil, err