Skip to content

Commit

Permalink
Changes for the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhamra1 committed Jul 14, 2023
1 parent feacd5b commit 2a3a530
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 85 deletions.
4 changes: 2 additions & 2 deletions dgraphtest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type GraphQLResponse struct {
Data json.RawMessage `json:"data,omitempty"`
Errors x.GqlErrorList `json:"errors,omitempty"`
Code string `json:"code"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
Extensions map[string]interface{} `json:"license,omitempty"`
}

type Location struct {
Expand Down Expand Up @@ -555,7 +555,7 @@ func (hc *HTTPClient) PostPersistentQuery(query, sha string) ([]byte, error) {

// Apply license using http endpoint
func (hc *HTTPClient) ApplyLicenseHTTP(licenseKey []byte) (*GraphQLResponse, error) {
respBody, err := hc.doPost(licenseKey, hc.licenseURL, "application/json")
respBody, err := hc.doPost(licenseKey, hc.licenseURL, "application/text")
if err != nil {
return nil, errors.Wrap(err, "error applying license")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.8.4
github.com/twpayne/go-geom v1.0.5
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c
go.etcd.io/etcd v0.5.0-alpha.5.0.20190108173120-83c051b701d3
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
Expand Down
11 changes: 3 additions & 8 deletions systest/license/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
type LicenseTestSuite struct {
suite.Suite
dc dgraphtest.Cluster
testData TestInp
}

func (lsuite *LicenseTestSuite) SetupTest() {
Expand All @@ -44,12 +43,8 @@ func (lsuite *LicenseTestSuite) Upgrade() {
}

func TestLicenseTestSuite(t *testing.T) {
var tsuite LicenseTestSuite
for _, tt := range tests {
tsuite.testData = tt
suite.Run(t, &tsuite)
if t.Failed() {
t.Fatal("TestLicenseTestSuite tests failed")
}
suite.Run(t, new(LicenseTestSuite))
if t.Failed() {
t.Fatal("TestLicenseTestSuite tests failed")
}
}
106 changes: 41 additions & 65 deletions systest/license/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/dgraph-io/dgraph/dgraphtest"
"github.com/dgraph-io/dgraph/x"
)

var expiredKey = []byte(`-----BEGIN PGP MESSAGE-----
Expand Down Expand Up @@ -68,36 +69,15 @@ I8jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm7mUd/5nzcU5QZU9yEEI=
-----END PGP MESSAGE-----
`)

type Location struct {
Line int `json:"line,omitempty"`
Column int `json:"column,omitempty"`
}

type GqlError struct {
Message string `json:"message"`
Locations []Location `json:"locations,omitempty"`
Path []interface{} `json:"path,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}

type GqlErrorList []*GqlError

type responseStruct struct {
Errors GqlErrorList `json:"errors"`
Code string `json:"code"`
Message string `json:"message"`
License map[string]interface{} `json:"license"`
}

type TestInp struct {
type testInp struct {
name string
licenseKey []byte
code string
user string
message string
}

var tests = []TestInp{
var tests = []testInp{
{
"Using expired entrerprise license key, should be able to extract user information",
expiredKey,
Expand Down Expand Up @@ -128,26 +108,24 @@ func (lsuite *LicenseTestSuite) TestEnterpriseLicenseWithHttpEndPoint() {

hcli, err := lsuite.dc.HTTPClient()
require.NoError(t, err)
tt := lsuite.testData
enterpriseResponse, err := hcli.ApplyLicenseHTTP(tt.licenseKey)
require.NoError(t, err)

// Check if the license is applied
require.Equal(t, enterpriseResponse.Code, tt.code)

if enterpriseResponse.Code == `Success` {
// Upgrade
lsuite.Upgrade()

hcli, err := lsuite.dc.HTTPClient()
require.NoError(t, err)

// check the user information in case the license is applied
// Expired license should not be enabled even after it is applied
assertLicenseNotEnabled(t, hcli, tt.user)
} else {
// check the error message in case the license is not applied
require.Equal(t, enterpriseResponse.Errors[0].Message, tt.message)
err = hcli.LoginIntoNamespace(dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)
require.NoError(t, err, "login with namespace failed")
require.NotNil(t, hcli.AccessJwt, "galaxy token is nil")

for _, tt := range tests {
enterpriseResponse, err := hcli.ApplyLicenseHTTP(tt.licenseKey)

if err == nil && enterpriseResponse.Code == `Success` {
// Check if the license is applied
require.Equal(t, enterpriseResponse.Code, tt.code)

// check the user information in case the license is applied
// Expired license should not be enabled even after it is applied
assertLicenseNotEnabled(t, hcli, tt.user)
} else {
// check the error message in case the license is not applied
require.Nil(t, enterpriseResponse)
}
}
}

Expand All @@ -157,28 +135,26 @@ func (lsuite *LicenseTestSuite) TestEnterpriseLicenseWithGraphqlEndPoint() {
t := lsuite.T()
hcli, err := lsuite.dc.HTTPClient()
require.NoError(t, err)

tt := lsuite.testData
resp, err := hcli.ApplyLicenseGraphQL(tt.licenseKey)
require.NoError(t, err)

if tt.code == `Success` {
// Check if the license is applied
dgraphtest.CompareJSON(`{"enterpriseLicense":{"response":{"code":"Success"}}}`, string(resp))

// Upgrade
lsuite.Upgrade()

hcli, err := lsuite.dc.HTTPClient()
require.NoError(t, err)

// check the user information in case the license is applied
// Expired license should not be enabled even after it is applied
assertLicenseNotEnabled(t, hcli, tt.user)
} else {
dgraphtest.CompareJSON(`{"enterpriseLicense":null}`, string(resp))
// check the error message in case the license is not applied
require.Contains(t, err, tt.message)
err = hcli.LoginIntoNamespace(dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)
require.NoError(t, err, "login with namespace failed")
require.NotNil(t, hcli.AccessJwt, "galaxy token is nil")

for _, tt := range tests {
resp, err := hcli.ApplyLicenseGraphQL(tt.licenseKey)

if tt.code == `Success` {
require.NoError(t, err)
// Check if the license is applied
dgraphtest.CompareJSON(`{"enterpriseLicense":{"response":{"code":"Success"}}}`, string(resp))

// check the user information in case the license is applied
// Expired license should not be enabled even after it is applied
assertLicenseNotEnabled(t, hcli, tt.user)
} else {
dgraphtest.CompareJSON(`{"enterpriseLicense":null}`, string(resp))
// check the error message in case the license is not applied
require.Contains(t, err.Error(), tt.message)
}
}
}

Expand Down
12 changes: 4 additions & 8 deletions systest/license/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type LicenseTestSuite struct {
dc dgraphtest.Cluster
lc *dgraphtest.LocalCluster
uc dgraphtest.UpgradeCombo
testData TestInp
}

func (lsuite *LicenseTestSuite) SetupTest() {
Expand Down Expand Up @@ -64,16 +63,13 @@ func (lsuite *LicenseTestSuite) Upgrade() {
}

func TestLicenseTestSuite(t *testing.T) {
for _, uc := range dgraphtest.AllUpgradeCombos {
for _, uc := range dgraphtest.AllUpgradeCombos() {
log.Printf("running: backup in [%v], restore in [%v]", uc.Before, uc.After)
var tsuite LicenseTestSuite
tsuite.uc = uc
for _, tt := range tests {
tsuite.testData = tt
suite.Run(t, &tsuite)
if t.Failed() {
t.Fatal("TestLicenseTestSuite tests failed")
}
suite.Run(t, &tsuite)
if t.Failed() {
t.Fatal("TestLicenseTestSuite tests failed")
}
}
}

0 comments on commit 2a3a530

Please sign in to comment.