1// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file.
5
6package travis
7
8import (
9	"context"
10	"fmt"
11	"net/http"
12	"reflect"
13	"testing"
14)
15
16func TestLintService_Lint(t *testing.T) {
17	client, mux, _, teardown := setup()
18	defer teardown()
19
20	mux.HandleFunc("/lint", func(w http.ResponseWriter, r *http.Request) {
21		testMethod(t, r, http.MethodPost)
22		testBody(t, r, `{"content":"foo:bar"}`+"\n")
23		fmt.Fprint(w, `{"warnings":[{"key":["test"],"message":"test!"}]}`)
24	})
25
26	warnings, _, err := client.Lint.Lint(context.Background(), &TravisYml{Content: "foo:bar"})
27
28	if err != nil {
29		t.Errorf("Lint.Lint returned error: %v", err)
30	}
31
32	want := []*Warning{{Key: []string{"test"}, Message: "test!"}}
33	if !reflect.DeepEqual(warnings, want) {
34		t.Errorf("Lint.Lint returned %+v, want %+v", warnings, want)
35	}
36}
37