Skip to content

Commit 960a804

Browse files
fix lint failures; upgrade deprecate io/ioutils package (FF-820) (#23)
1 parent 830325f commit 960a804

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ eppo-golang-sdk-*
1414

1515
# Dependency directories (remove the comment below to include it)
1616
# vendor/
17-
eppoclient/test-data/assignment-v2
18-
eppoclient/test-data/rac-experiments-v2.json
17+
eppoclient/test-data
1918
.vscode
19+
20+
.DS_Store

eppoclient/client_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eppoclient
22

33
import (
4+
"log"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -15,15 +16,25 @@ func Test_AssignBlankExperiment(t *testing.T) {
1516
var mockLogger = new(mockLogger)
1617
client := newEppoClient(mockConfigRequestor, mockLogger)
1718

18-
assert.Panics(t, func() { client.GetAssignment("subject-1", "", dictionary{}) })
19+
assert.Panics(t, func() {
20+
_, err := client.GetAssignment("subject-1", "", dictionary{})
21+
if err != nil {
22+
log.Println(err)
23+
}
24+
})
1925
}
2026

2127
func Test_AssignBlankSubject(t *testing.T) {
2228
var mockConfigRequestor = new(mockConfigRequestor)
2329
var mockLogger = new(mockLogger)
2430
client := newEppoClient(mockConfigRequestor, mockLogger)
2531

26-
assert.Panics(t, func() { client.GetAssignment("", "experiment-1", dictionary{}) })
32+
assert.Panics(t, func() {
33+
_, err := client.GetAssignment("", "experiment-1", dictionary{})
34+
if err != nil {
35+
log.Println(err)
36+
}
37+
})
2738
}
2839

2940
func Test_SubjectNotInSample(t *testing.T) {

eppoclient/configurationstore.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ func (cs *configurationStore) GetConfiguration(key string) (expConfig experiment
5959
log.Fatalln("Incorrect json")
6060
}
6161
ec := experimentConfiguration{}
62-
json.Unmarshal(jsonString, &ec)
62+
err = json.Unmarshal(jsonString, &ec)
63+
if err != nil {
64+
log.Fatalln("failure to unmarshal json into experiment configuration")
65+
}
6366

6467
return ec, nil
6568
}

eppoclient/eppoclient_e2e_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package eppoclient
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"os"
@@ -62,7 +62,10 @@ func initFixture() string {
6262
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6363
switch strings.TrimSpace(r.URL.Path) {
6464
case "/randomized_assignment/v3/config":
65-
json.NewEncoder(w).Encode(testResponse)
65+
err := json.NewEncoder(w).Encode(testResponse)
66+
if err != nil {
67+
fmt.Println("Error encoding test response")
68+
}
6669
default:
6770
http.NotFoundHandler().ServeHTTP(w, r)
6871
}
@@ -72,7 +75,7 @@ func initFixture() string {
7275
}
7376

7477
func getTestData() dictionary {
75-
files, err := ioutil.ReadDir(TEST_DATA_DIR)
78+
files, err := os.ReadDir(TEST_DATA_DIR)
7679

7780
if err != nil {
7881
panic("test cases files read error")
@@ -88,15 +91,22 @@ func getTestData() dictionary {
8891
defer jsonFile.Close()
8992

9093
testCaseDict := testData{}
91-
byteValue, _ := ioutil.ReadAll(jsonFile)
92-
json.Unmarshal(byteValue, &testCaseDict)
94+
byteValue, _ := io.ReadAll(jsonFile)
95+
err = json.Unmarshal(byteValue, &testCaseDict)
96+
if err != nil {
97+
fmt.Println("Error reading test case file")
98+
}
9399
tstData = append(tstData, testCaseDict)
94100
}
95101

96102
var racResponseData map[string]interface{}
97103
racResponseJsonFile, _ := os.Open(MOCK_RAC_RESPONSE_FILE)
98-
byteValue, _ := ioutil.ReadAll(racResponseJsonFile)
104+
byteValue, _ := io.ReadAll(racResponseJsonFile)
99105
err = json.Unmarshal(byteValue, &racResponseData)
106+
if err != nil {
107+
fmt.Println("Error reading mock RAC response file")
108+
}
109+
100110
if err != nil {
101111
fmt.Println("Error reading mock RAC response file")
102112
}

eppoclient/httpclient.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ type SDKParams struct {
2323
sdkVersion string
2424
}
2525

26-
// todo move this to requestor
27-
type experiment struct {
28-
Name string
29-
Latest string
30-
}
31-
32-
type experiments struct {
33-
Results []*experiment
34-
}
35-
3626
func newHttpClient(baseUrl string, client *http.Client, sdkParams SDKParams) *httpClient {
3727
var hc = &httpClient{
3828
baseUrl: baseUrl,

0 commit comments

Comments
 (0)