github.com/ryicoh/apery-graphql@v0.0.0-20210919090814-a8c219904bee/pkg/apery/client_test.go (about)

     1  package apery
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func TestEvaluate(t *testing.T) {
    11  	if err := os.Chdir("../.."); err != nil {
    12  		t.Fatal(err)
    13  	}
    14  
    15  	cli := NewAperyClient("apery")
    16  
    17  	var tests = []struct {
    18  		name           string
    19  		expectValue    int
    20  		expectBestmove string
    21  		expectErr      error
    22  		given          string
    23  	}{
    24  		{"", 87, "2g2f", nil, "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL w - 1"},
    25  	}
    26  	for _, tt := range tests {
    27  		tt := tt
    28  		t.Run(tt.name, func(t *testing.T) {
    29  			ctx, cancel := context.WithTimeout(context.TODO(), 60*time.Second)
    30  			defer cancel()
    31  
    32  			res, err := cli.Evaluate(ctx, tt.given, []string{"7g7f", "3c3d", "2g2f"}, 1*time.Second)
    33  
    34  			if res.Value != tt.expectValue {
    35  				t.Errorf("(%s): expected %d, actual %d", tt.given, tt.expectValue, res.Value)
    36  			}
    37  			if res.Bestmove != tt.expectBestmove {
    38  				t.Errorf("(%s): expected %s, actual %s", tt.given, tt.expectBestmove, res.Bestmove)
    39  			}
    40  			if err != tt.expectErr {
    41  				t.Errorf("(%s): expected %v, actual %v", tt.given, tt.expectErr, err)
    42  			}
    43  		})
    44  	}
    45  }