From 52cbac4a9d7b257a2f10e7178d36c0d9f1761e40 Mon Sep 17 00:00:00 2001 From: kubitre Date: Tue, 22 Sep 2020 17:07:14 +0700 Subject: [PATCH] enhanced tests and some fixtures on pipeline --- go.mod | 3 ++ go.sum | 8 +++++ pipeline/pipeline_test.go | 65 +++++++++++++++++++++++++++++++++++++++ tags/parser_test.go | 65 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) diff --git a/go.mod b/go.mod index 7c0e285..0e61cc6 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,10 @@ module github.com/goreflect/gostructor go 1.13 require ( + github.com/google/go-cmp v0.5.2 // indirect github.com/goreflect/go_hocon v0.0.2 + github.com/pkg/errors v0.9.1 // indirect github.com/sirupsen/logrus v1.5.0 github.com/stretchr/testify v1.5.1 + gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index 7c3ea9e..95073a4 100644 --- a/go.sum +++ b/go.sum @@ -6,12 +6,16 @@ github.com/go-akka/configuration v0.0.0-20190919102339-a31c845c4b1b h1:3tSuByOnO github.com/go-akka/configuration v0.0.0-20190919102339-a31c845c4b1b/go.mod h1:19bUnum2ZAeftfwwLZ/wRe7idyfoW2MfmXO464Hrfbw= github.com/go-akka/configuration v0.0.0-20200115015912-550403a6bd87 h1:qsA6HPoRXYJ1a2fsHVUmieRTg+otMAM4wEJgSWzumL8= github.com/go-akka/configuration v0.0.0-20200115015912-550403a6bd87/go.mod h1:19bUnum2ZAeftfwwLZ/wRe7idyfoW2MfmXO464Hrfbw= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/goreflect/go_hocon v0.0.1 h1:n05o2/7F4S2Q6ZOnn02Sm3kEj/zmkvThk2m7uQQ1Ong= github.com/goreflect/go_hocon v0.0.1/go.mod h1:+Ty2MKNMIhPNLYWpO4BqpH0W9qZOhKB/upHgEYAlRB8= github.com/goreflect/go_hocon v0.0.2 h1:8r5kdjE4iG+Hfv1qScSR2LUNcwUwTmFdqpCN/yKY/uA= github.com/goreflect/go_hocon v0.0.2/go.mod h1:Pw26F1wCoERtcchtIfjcTLO/wb9slw11ZSCvUbOgrYU= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= @@ -31,6 +35,10 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools v1.4.0 h1:BjtEgfuw8Qyd+jPvQz8CfoxiO/UjFEidWinwEXZiWv0= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= diff --git a/pipeline/pipeline_test.go b/pipeline/pipeline_test.go index d1b15e5..c042f48 100644 --- a/pipeline/pipeline_test.go +++ b/pipeline/pipeline_test.go @@ -690,3 +690,68 @@ func TestPipeline_recursiveParseFields(t *testing.T) { }) } } + +func TestPipeline_setNextChain(t *testing.T) { + type fields struct { + chains *Chain + errors []string + sourcesTypes []int + curentChain *Chain + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + { + name: "correct changed current stage function", + fields: fields{ + chains: &Chain{ + stageFunction: EnvironmentConfig{}, + next: nil, + }, + errors: nil, + sourcesTypes: nil, + curentChain: nil, + }, + wantErr: false, + }, + { + name: "incorrect change current stage function", + fields: fields{ + chains: &Chain{ + next: nil, + }, + curentChain: &Chain{ + stageFunction: EnvironmentConfig{}, + }, + }, + wantErr: true, + }, + { + name: "correct change current stage function", + fields: fields{ + curentChain: &Chain{ + stageFunction: EnvironmentConfig{}, + next: &Chain{ + stageFunction: &DefaultConfig{}, + }, + }, + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + pipeline := &Pipeline{ + chains: tt.fields.chains, + errors: tt.fields.errors, + sourcesTypes: tt.fields.sourcesTypes, + curentChain: tt.fields.curentChain, + } + if err := pipeline.setNextChain(); (err != nil) != tt.wantErr { + t.Errorf("Pipeline.setNextChain() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/tags/parser_test.go b/tags/parser_test.go index 614599c..293f9d5 100644 --- a/tags/parser_test.go +++ b/tags/parser_test.go @@ -1,6 +1,7 @@ package tags import ( + "reflect" "strings" "testing" ) @@ -145,3 +146,67 @@ func TestParser_Scan(t *testing.T) { // parsedSlice, // ) } + +func TestParser_parsePathAsSingleValue(t *testing.T) { + type fields struct { + Lexer *Scanner + Buffer struct{ AmountLetters int } + Term TerminalSymbol + } + tests := []struct { + name string + fields fields + wantPath Path + wantErr bool + }{ + { + name: "completed parsed path", + fields: fields{ + Lexer: &Scanner{ + r: nil, + CurrentPosition: 0, + }, + Buffer: struct{ AmountLetters int }{ + AmountLetters: 1, + }, + Term: TerminalSymbol{ + Tok: FUNCTION, + Literal: "test", + StartPositioin: 0, + EndPosition: 4, + }, + }, + wantPath: Path{ + TerminalSymbol: TerminalSymbol{ + Tok: PATH, + Literal: "test", + StartPositioin: 0, + EndPosition: 4, + }, + PathName: TerminalSymbol{ + Tok: FUNCTION, + Literal: "test", + StartPositioin: 0, + EndPosition: 4, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + parser := &Parser{ + Lexer: tt.fields.Lexer, + Buffer: tt.fields.Buffer, + Term: tt.fields.Term, + } + gotPath, err := parser.parsePathAsSingleValue() + if (err != nil) != tt.wantErr { + t.Errorf("Parser.parsePathAsSingleValue() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(gotPath, tt.wantPath) { + t.Errorf("Parser.parsePathAsSingleValue() = %v, want %v", gotPath, tt.wantPath) + } + }) + } +}