<commit_before>// Copyright 2016 <NAME>.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ht

import (
	"database/sql"
	"flag"
	"fmt"
	"net/http"
	"net/url"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"testing"
	"time"

	_ "github.com/go-sql-driver/mysql"
)

// ----------------------------------------------------------------------------
// file:// pseudo request.

func TestFilePseudorequest(t *testing.T) {
	wd, err := os.Getwd()
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	p := filepath.ToSlash(wd) + "/testdata/fileprotocol"
	u := "file://"
	if runtime.GOOS == "windows" {
		u += "/"
	}
	u += p

	linuxOrWinNotFound := []Check{
		&Body{Contains: "not a directory"},        // Linux
		&Body{Contains: "system cannot find the"}, // Windows
	}

	tests := []*Test{
		{
			Name: "PUT_okay",
			Request: Request{
				URL:  u,
				Body: "Tadadadaaa!",
			},
			Checks: []Check{
				StatusCode{Expect: 200},
				&Body{Prefix: "Successfully wrote " + u},
			},
		},
		{
			Name: "PUT_forbidden",
			Request: Request{
				URL:  u + "/iouer/cxxs/dlkfj",
				Body: "Tadadadaaa!",
			},
			Checks: []Check{
				StatusCode{Expect: 403},
				&Body{Contains: p},
				AnyOne{Of: linuxOrWinNotFound},
			},
		},
		{
			Name: "GET_okay",
			Request: Request{
				URL: u,
			},
			Checks: []Check{
				StatusCode{Expect: 200},
				&Body{Equals: "Tadadadaaa!"},
			},
		},
		{
			Name: "GET_wrongdir",
			Request: Request{
				URL: u + "/slfer/mxcmdk",
			},
			Checks: []Check{
				StatusCode{Expect: 404},
				&Body{Contains: p},
				AnyOne{Of: linuxOrWinNotFound},
			},
		},
		{
			Name: "GET_notfound",
			Request: Request{
				URL: u + "dfkewirxym",
			},
			Checks: []Check{
				StatusCode{Expect: 404},
				&Body{Contains: p},
				AnyOne{Of: linuxOrWinNotFound},<commit_msg>ht: re-fix tests for file:// pseudo requests<commit_after>// Copyright 2016 <NAME>.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ht

import (
	"database/sql"
	"flag"
	"fmt"
	"net/http"
	"net/url"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"testing"
	"time"

	_ "github.com/go-sql-driver/mysql"
)

// ----------------------------------------------------------------------------
// file:// pseudo request.

func TestFilePseudorequest(t *testing.T) {
	wd, err := os.Getwd()
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	p := filepath.ToSlash(wd) + "/testdata/fileprotocol"
	u := "file://"
	if runtime.GOOS == "windows" {
		u += "/"
	}
	u += p

	linuxOrWinNotADir := []Check{
		&Body{Contains: "not a directory"},        // Linux
		&Body{Contains: "system cannot find the"}, // Windows
	}
	linuxOrWinNotFound := []Check{
		&Body{Contains: "no such file or directory"}, // Linux
		&Body{Contains: "system cannot find the"},    // Windows
	}

	tests := []*Test{
		{
			Name: "PUT_okay",
			Request: Request{
				URL:  u,
				Body: "Tadadadaaa!",
			},
			Checks: []Check{
				StatusCode{Expect: 200},
				&Body{Prefix: "Successfully wrote " + u},
			},
		},
		{
			Name: "PUT_forbidden",
			Request: Request{
				URL:  u + "/iouer/cxxs/dlkfj",
				Body: "Tadadadaaa!",
			},
			Checks: []Check{
				StatusCode{Expect: 403},
				&Body{Contains: p},
				AnyOne{Of: linuxOrWinNotADir},
			},
		},
		{
			Name: "GET_okay",
			Request: Request{
				URL: u,
			},
			Checks: []Check{
				StatusCode{Expect: 200},
				&Body{Equals: "Tadadadaaa!"},
			},
		},
		{
			Name: "GET_wrongdir",
			Request: Request{
				URL: u + "/slfer/mxcmdk",
			},
			Checks: []Check{
				StatusCode{Expect: 404},
				&Body{Contains: p},
				AnyOne{Of: linuxOrWinNotADir},
			},
		},
		{
			Name: "GET_notfound",
			Request: Request{
				URL: u + "dfkewirxym",
			},
			Checks: []Check{
				StatusCode{Expect: 404},
				&Body{Contains: p},
				AnyOne{Of: linuxOrWinNotFound},
{'fraction_non_alphanumeric': 0.2093853608773272, 'fraction_numerical': 0.009691405253761795, 'mean_word_length': 2.4585537918871254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '763058', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1467, 'n_words': 339}