<commit_before>// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ctfe

import (
	"strings"
	"testing"
	"time"
)

func TestSetUpInstance(t *testing.T) {
	var tests = []struct {
		desc   string
		cfg    LogConfig
		errStr string
	}{
		{
			desc: "valid",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
		},
		{
			desc: "no-roots",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "specify RootsPEMFile",
		},
		{
			desc: "no-priv-key",
			cfg: LogConfig{
				LogID:        1,
				Prefix:       "log",
				RootsPEMFile: []string{"../../testdata/fake-ca.cert"},
			},
			errStr: "specify PrivKeyPEMFile",
		},
		{
			desc: "missing-root-cert",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/bogus.cert"},
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "failed to read trusted roots",
		},
		{
			desc: "missing-privkey",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../../testdata/bogus.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "failed to load private key",
		},
		{
			desc: "privkey-wrong-password",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "failed to load private key",
		},
		{
			desc: "valid-ekus-1",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any"},
			},
		},
		{
			desc: "valid-ekus-2",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any", "ServerAuth", "TimeStamping"},
			},
		},
		{
			desc: "invalid-ekus-1",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any", "ServerAuth", "TimeStomping"},
			},
			errStr: "unknown extended key usage",
		},
		{
			desc: "invalid-ekus-2",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any "},
			},
			errStr: "unknown extended key usage",
		},
	}

	for _, test := range tests {
		_, err := test.cfg.SetUpInstance(nil, time.Second)
		if err != nil {
			if test.errStr == "" {
				t.Errorf("(%v).SetUpInstance()=_,%v; want _,nil", test.desc, err)
			} else if !strings.Contains(err.Error(), test.errStr) {
				t.Errorf("(%v).SetUpInstance()=_,%v; want err containing %q", test.desc, err, test.errStr)
			}
			continue
		}
		if test.errStr != "" {
			t.Errorf("(%v).SetUpInstance()=_,mo;; want err containing %q", test.desc, test.errStr)
		}
	}

}
<commit_msg>Update test for local testdata location<commit_after>// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ctfe

import (
	"strings"
	"testing"
	"time"
)

func TestSetUpInstance(t *testing.T) {
	var tests = []struct {
		desc   string
		cfg    LogConfig
		errStr string
	}{
		{
			desc: "valid",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
		},
		{
			desc: "no-roots",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "specify RootsPEMFile",
		},
		{
			desc: "no-priv-key",
			cfg: LogConfig{
				LogID:        1,
				Prefix:       "log",
				RootsPEMFile: []string{"../testdata/fake-ca.cert"},
			},
			errStr: "specify PrivKeyPEMFile",
		},
		{
			desc: "missing-root-cert",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/bogus.cert"},
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "failed to read trusted roots",
		},
		{
			desc: "missing-privkey",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../testdata/bogus.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "failed to load private key",
		},
		{
			desc: "privkey-wrong-password",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
			},
			errStr: "failed to load private key",
		},
		{
			desc: "valid-ekus-1",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any"},
			},
		},
		{
			desc: "valid-ekus-2",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any", "ServerAuth", "TimeStamping"},
			},
		},
		{
			desc: "invalid-ekus-1",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any", "ServerAuth", "TimeStomping"},
			},
			errStr: "unknown extended key usage",
		},
		{
			desc: "invalid-ekus-2",
			cfg: LogConfig{
				LogID:           1,
				Prefix:          "log",
				RootsPEMFile:    []string{"../testdata/fake-ca.cert"},
				PrivKeyPEMFile:  "../testdata/ct-http-server.privkey.pem",
				PrivKeyPassword: "<PASSWORD>",
				ExtKeyUsages:    []string{"Any "},
			},
			errStr: "unknown extended key usage",
		},
	}

	for _, test := range tests {
		_, err := test.cfg.SetUpInstance(nil, time.Second)
		if err != nil {
			if test.errStr == "" {
				t.Errorf("(%v).SetUpInstance()=_,%v; want _,nil", test.desc, err)
			} else if !strings.Contains(err.Error(), test.errStr) {
				t.Errorf("(%v).SetUpInstance()=_,%v; want err containing %q", test.desc, err, test.errStr)
			}
			continue
		}
		if test.errStr != "" {
			t.Errorf("(%v).SetUpInstance()=_,mo;; want err containing %q", test.desc, test.errStr)
		}
	}

}

{'fraction_non_alphanumeric': 0.1719072756483819, 'fraction_numerical': 0.005049345880192793, 'mean_word_length': 2.4392265193370166, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3286037', 'n_tokens_mistral': 3579, 'n_tokens_neox': 3034, 'n_words': 651}